package com.toobigtofail.entities
{
	import net.flashpunk.Entity;
	import net.flashpunk.FP;
	import net.flashpunk.Graphic;
	import net.flashpunk.Mask;
	import net.flashpunk.graphics.Image;
	
	public class Background extends Entity
	{
		[Embed(source="/assets/gfx/background.png")] private static const BACKGROUND_IMG:Class;
		
		private var _image:Image = new Image(BACKGROUND_IMG);
		
		private var _isFlicker:Boolean = false;
		private var _flickerTimer:Number = 0;
		private var _flickerTime:Number;
		
		public function Background(x:Number=0, y:Number=0, graphic:Graphic=null, mask:Mask=null)
		{
		
			graphic = _image;
			super(x, y, graphic, mask);
		}
		
		override public function update():void
		{
			super.update();
			
			if(_isFlicker)
			{
				_flickerTimer += FP.elapsed;
				if(_flickerTimer > _flickerTime)
				{
					_isFlicker = false;
					_image.color = 0xFFFFFF;
				}
			}
			
		}
		
		public function flicker(color:uint, flickerTime:Number):void
		{
			_isFlicker = true;
			_image.color = color;
		}
	}
}